package com.xiaohudie.SGGJUC;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

/**
 * @Author xiao hu die
 * @Date 2022/3/10 14:26
 * @Version 1.0
 */
public class TestSynchronusQueue {

    public static void main(String[] args) {
        SynchronousQueue<String> strings = new SynchronousQueue<>();
        new Thread(()->{
            try {
                strings.put(Thread.currentThread().getName());
                strings.put(Thread.currentThread().getName());
                strings.put(Thread.currentThread().getName());
                System.out.println("放入完毕");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"刘碟").start();
      new Thread(()->{
          System.out.println(Thread.currentThread().getName() +strings.poll());
          try {
              TimeUnit.SECONDS.sleep(3);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          System.out.println(Thread.currentThread().getName() +strings.poll());
          System.out.println(Thread.currentThread().getName() +strings.poll());
      },"陈唯一").start();
    }
}
 class   TestSynchronQueue{
    private static SynchronousQueue<String> stringSynchronousQueue =new SynchronousQueue<>();
    private static void setSynch() throws InterruptedException {
        stringSynchronousQueue.put("1");
        stringSynchronousQueue.put("2");
        stringSynchronousQueue.put("3");
    }
    private static void getSynch(){
        System.out.println(stringSynchronousQueue.poll());
        System.out.println(stringSynchronousQueue.poll());
        System.out.println(stringSynchronousQueue.poll());
    }
}
